<#include "../inc/inc.ftl"/>
<@html title_="登录" fontawesome=true css_=['login/reset.css','login/supersized.css','login/style.css']
script_=['login/jquery-1.8.2.min.js','login/supersized.3.2.7.min.js','login/supersized-init.js','login/scripts.js']>
<div class="page-container">
    <h1>登录</h1>
    <form id="registerForm" action="${root}/login" method="post">
        <input type="text" name="username" id="username" class="username" style="ime-mode:disabled" onpaste="return false" ondragenter="return false"   maxlength="32" placeholder="请输入昵称">
        <input type="password" name="password" id="password" class="password" maxlength="32" placeholder="请输入密码">
        <button type="button" id="btn">登录</button>
        <div class="error"><span>+</span></div>
    </form>
</div>

</body>


<@script_>
<script>
    $("#getCode").click(function(){
        var email = $("#email").val();
        $.ajax({
            url:"${root}/send/email",
            data:{"email":email},
            success : function(data){
            }
        })
    });

    $("#btn").click(function(){

        var email = $("#email").val();
        var username = $("#username").val(),password = $("#password").val();
        $.ajax({
            url:"${root}/login",
            type: 'POST',
            data:{"email":email,"username":username,"password":password},
            success : function(data){
                console.log(data)
                if(data.code==0){
                    layer.msg(data.msg, {
                        time: 0 //不自动关闭
                        ,btn: ['前往登录', '不登录']
                        ,yes: function(index){
                            layer.close(index);
                            window.location.href="${root}/login";
                        }
                    });
                }else{
                    layer.msg(data.msg)
                }
            },error:function (data) {
                layer.msg("系统错误!")
            }
        })
    });

    function checkCode() {
        var check = false;
        var code = $("#imageCode").val();
        if(!code && code.length != 4){
            return check;
        }
        var options = {
            url:  '${root}/api/captcha/check?imageCode='+$("#imageCode").val(),
            async: false,
            success : function(data){
                if(data == '1'){
                    check = true;
                }
            }
        };
        $.ajax(options);
        return check;

    }
</script>
</@script_>
</@html>